﻿using System.ServiceModel.Activation;
using MyFloridaHouse.libServiceBusinessRules;
using MyFloridaHouse.libSTO;
using MyFloridaHouse.libSvDTO;
using System;

namespace MyFloridaHouse.MapServer
{
	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
	public class DistrBldr : IDistrBldr
	{

        /// <summary>
        /// Gets the census geometry
        /// </summary>
        /// <returns>Object: <see cref="CensusGeometrySTO"/></returns>
        public CensusGeometrySTO StartupGetCensusGeometry(DateTime clientFileTimestamp)
        {
            return CensusGeometry.GetCensusGeometry(clientFileTimestamp);
        }

        /// <summary>
        /// Gets the district plan types.
        /// </summary>
        /// <returns>Object: <see cref="DistrictPlanTypeSTO"/></returns>
        public DistrictPlanTypeSTO StartupGetDistrictPlanTypes(DateTime clientFileTimestamp)
		{
            return DistrictPlanTypes.GetDistrictPlanTypes(clientFileTimestamp);
		}

        /// <summary>
        /// Gets the layers.
        /// </summary>
        /// <returns>Object: <see cref="LayerSTO"/></returns>
        public LayerSTO StartupGetLayers()
        {
            return AppLayers.GetLayers();
        }

		#region Azure Storage Enable Methods (5/2011)

		/// <summary>
		/// Gets the file. District plans (existing) are fixed and have been compressed and stored
		/// as blobs in azure storage. The <see cref="FileInfoDTO"/> blob to get from storage. The
		/// plan name to be retreived is sourced from storage using the FileInfoSTO GetFileInfo() method.
		/// Executed only once per session.
		/// 1 (occasional)
		/// Azure storage enabled 05/2011
		/// </summary>
		/// <param name="fileToGet"><see cref="FileInfoDTO"/> that is the plan stored as a blob. The file (blob) to get.</param>
		/// <returns>Object: <see cref="FileSTO"/></returns>
		public FileSTO GetFile(FileInfoDTO fileToGet)
		{
			return File.GetFile(fileToGet);
		}

		/// <summary>
		/// Gets the file info. District plans are stored as blobs as named objects. This method returns
		/// a list of info object that are used to populate a user screen control. The user select a plan
		/// which is in turn passed to the FileSTO GetFile method as a parameter.
		/// Executed only once per session.
		/// 1 (occasional)
		/// Azure storage enabled 05/2011
		/// </summary>
		/// <returns>Object: <see cref="FileInfoSTO"/></returns>
		public FileInfoSTO GetFileInfo()
		{
			return File.GetFileInfo();
		}




		#endregion

		/// <summary>
		/// Gets the district plan. Data is store in blob storage.
		/// The blob is cached on the local user's isolated storage in Silverlight.
		/// Thus if the object is present and still current it is not loaded again.
		/// A ref is appended so that the cached name can be compared with the current storage version.
		/// Executed only once per session.
		/// </summary>
		/// <param name="iDistrictPlanFileName">Name of the district plan file.</param>
		/// <returns>Object: <see cref="DistictPlanSTO"/></returns>
        //public DistictPlanSTO GetDistrictPlan(string iDistrictPlanFileName)
        //{
        //    return DistrictPlan.GetDistrictPlan(iDistrictPlanFileName);
        //}

		/// <summary>
		/// Gets the shape uogIDs as a list of ShapeUogIDDTO objects. Called every time you build a district - bad boy
		/// </summary>
		/// <param name="iWktList">The iWKtlist.</param>
		/// <param name="iLayerID">The iLayerID.</param>
		/// <param name="iDistrictID">The iDistrictID.</param>
		/// <returns>Object: <see cref="ShapeUogidSTO"/></returns>
		public ShapeUogidSTO GetShapeUogIDs(string iWktList, int iLayerID, int iDistrictID)
		{
			return ShapeUogIDs.GetShapeUogIDs(iWktList, iLayerID, iDistrictID);
		}

		/// <summary>
		/// Gets the district shape. Called every time you build a district - bad boy
		/// </summary>
		/// <param name="compressedShapeList">The compressed shape list.</param>
		/// <param name="districtID">The district ID.</param>
		/// <returns>Object: <see cref="DistrictShapeSTO"/></returns>
		public DistrictShapeSTO GetDistrictShape(byte[] compressedShapeList, int districtID)
		{
			return DistrictShape.GetDistrictShape(compressedShapeList, districtID);
		}

		/// <summary>
		/// Gets the district data summary. Called every time you build a district - bad boy
		/// </summary>
		/// <param name="iDistrictID">The i district ID.</param>
		/// <param name="compressediRegionIDList">The compressedi region ID list.</param>
		/// <param name="iSourceLayerIDList">The i source layer ID list.</param>
		/// <param name="iDictionaryIDList">The i dictionary ID list.</param>
		/// <returns>Object: <see cref="DistrictShapeSTO"/></returns>
		public DistrictDataSummarySTO GetDistrictDataSummary(int iDistrictID, byte[] compressediRegionIDList, string iSourceLayerIDList, string iDictionaryIDList)
		{
			return DistrictDataSummary.GetDistrictDataSummary(iDistrictID, compressediRegionIDList, iSourceLayerIDList, iDictionaryIDList);
		}

		/// <summary>
		/// Gets the ACS (American Community Survey) district data summary.
		/// 1 occasional
		/// </summary>
		/// <param name="iDistrictID">The i district ID.</param>
		/// <param name="compressediRegionIDList">The compressedi region ID list.</param>
		/// <param name="iSourceLayerID">The i source layer ID.</param>
		/// <param name="iTableIDList">The i table ID list.</param>
		/// <returns>Object: <see cref="ACSDistrictSummaryReportSTO"/></returns>
		public ACSDistrictSummaryReportSTO GetACSDistrictDataSummary(int iDistrictID, byte[] compressediRegionIDList, string iSourceLayerID, string iTableIDList)
		{
			return Report.GetACSDistrictDataSummary(iDistrictID, compressediRegionIDList, iSourceLayerID, iTableIDList);
		}

		/// <summary>
		/// Gets the ACS (American Community Survey) report definition.
		/// 1 shot from mass data report (when it starts)
		/// </summary>
		/// <returns>Object: <see cref="ACSDistrictSummaryReportDefinitionSTO"/></returns>
		public ACSDistrictSummaryReportDefinitionSTO GetACSReportDefinition()
		{
			return Report.GetACSReportDefinition();
		}

		/// <summary>
		/// Gets the region data list.
		/// ?
		/// </summary>
		/// <param name="iLayerID">The ilayerID.</param>
		/// <param name="iRegionID">The iregionID.</param>
		/// <returns>Object: <see cref="RegionDataListSTO"/></returns>
		public RegionDataListSTO GetRegionDataList(int iLayerID, int iRegionID)
		{
			return RegionData.GetRegionDataList(iLayerID, iRegionID);
		}

		/// <summary>
		/// Gets the layer regions shapes in view.
		/// Everytime map is moved
		/// </summary>
		/// <param name="iZoomLevel">The i zoom level.</param>
		/// <param name="iLayerID">The i layer ID.</param>
		/// <param name="iNorth">The i north.</param>
		/// <param name="iEast">The i east.</param>
		/// <param name="iSouth">The i south.</param>
		/// <param name="iWest">The i west.</param>
		/// <returns></returns>
		public LayerRegionsShapesSTO GetLayerRegionsShapesInView(double iZoomLevel, int iLayerID, double iNorth, double iEast, double iSouth, double iWest)
		{
			return BoundingBoxRegions.GetLayerRegionsShapesInView(iZoomLevel, iLayerID, iNorth, iEast, iSouth, iWest);
		}

		/// <summary>
		/// Gets the layer regions data in view.
		/// Everytime map is moved
		/// </summary>
		/// <param name="iTargetLayerID">The i target layer ID.</param>
		/// <param name="iRegionIDList">The i region ID list.</param>
		/// <param name="iSourceLayerIDList">The i source layer ID list.</param>
		/// <param name="iDictionaryIDList">The i dictionary ID list.</param>
		/// <returns></returns>
		public LayerRegionsDataSTO GetLayerRegionsDataInView(int iTargetLayerID, string iRegionIDList, string iSourceLayerIDList, string iDictionaryIDList)
		{
			return BoundingBoxRegions.GetLayerRegionsDataInView(iTargetLayerID, iRegionIDList, iSourceLayerIDList, iDictionaryIDList);
		}

		//Todo: Future code.
		#region Future code

		/// <summary>
		/// [Future] 
		/// Gets the data dictionary denominators.
		/// </summary>
		/// <param name="iDataPartIDList">The i data part ID list.</param>
		/// <returns></returns>
		/// <remarks>This method is never called from WCF.</remarks>
		public DataDictionaryDenominatorSTO GetDataDictionaryDenominators(string iDataPartIDList)
		{
			return DataDictionary.GetDataDictionaryDenominators(iDataPartIDList);
		}

		/// <summary>
		/// [Future] 
		/// Gets the data dictionary parts.
		/// </summary>
		/// <returns></returns>
		/// <remarks>This method is never called from WCF.</remarks>
		public DataDictionaryPartSTO GetDataDictionaryParts()
		{
			return DataDictionary.GetDataDictionaryParts();
		}

		/// <summary>
		/// [Future] 
		/// Gets the layer data dictionary.
		/// </summary>
		/// <returns></returns>
		/// <remarks>This method is never called from WCF.</remarks>
		public DataDictionarySTO GetLayerDataDictionary()
		{
			return DataDictionary.GetLayerDataDictionary();
		}

		#endregion

	}
}
